<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\Url;
use backend\models\ItemType;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\ItemTypeSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Item Types');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="item-type-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a(Yii::t('app', 'Create Item Type'), ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <div class="wrapper">
        <div class="row">
            <div class="col-sm-12">
                <section class="panel">
                    <div class="panel-body">
                        <table class="table">
                            <thead>
                            <tr>
                                <th>Id</th>
                                <th>Pid</th>
                                <th>name</th>
                                <th>排序</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php foreach($models as $model){ ?>
                                <tr>
                                    <td><?php echo $model->id; ?></td>
                                    <td><?php echo $model->pid; ?></td>
                                    <td><?php echo $model->name; ?></td>
                                    <td><?php echo $model->sort; ?></td>
                                    <td><a href="<?php echo Url::to(['itemtype/update','id'=>$model->id]); ?>">修改</a>/<a href="<?php echo Url::to(['itemtype/delete','id'=>$model->id]); ?>">删除</a></td>
                                </tr>
                                <?php
                                    $models_children = ItemType::find()->where(['pid'=>$model->id])->all();
                                    if($models_children){
                                        foreach($models_children as $value){
                                ?>
                                 <tr>
                                    <td><?php echo $value->id; ?></td>
                                    <td><?php echo $value->pid; ?></td>
                                    <td><?php echo '-------------'.$value->name; ?></td>
                                    <td><?php echo $value->sort; ?></td>
                                    <td><a href="<?php echo Url::to(['itemtype/update','id'=>$value->id]); ?>">修改</a>/<a href="<?php echo Url::to(['itemtype/delete','id'=>$model->id]); ?>">删除</a></td>
                                </tr>
                            <?php } } } ?>
                            </tbody>
                        </table>
                    </div>

                </section>
            </div>
        </div>

    </div>
</div>
